package com.rybbaby.tss.platform.sysHandlePermissionsAttrs.service.imp;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.rybbaby.tss.core.utils.AjaxJsonResponse;
import com.rybbaby.tss.core.utils.StringUtils;
import com.rybbaby.tss.core.web.service.imp.BaseServiceImp;
import com.rybbaby.tss.platform.sysHandlePermissionsAttrs.entity.SysHandlePermissionsAttrs;
import com.rybbaby.tss.platform.sysHandlePermissionsAttrs.service.ISysHandlePermissionsAttrsService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * @description 操作权限html元素自定义属性数据库操作服务实现
 *
 * @author 谢进伟
 *
 * @createDate 2016-11-10 下午6:13:54
 */
@Service
@Transactional
public class SysHandlePermissionsAttrsServiceImp extends BaseServiceImp<SysHandlePermissionsAttrs> implements ISysHandlePermissionsAttrsService {
	
	@Override
	public List<Map<String , Object>> handlePermissionIdDatasource() {
		String sql1 = "SELECT id,name FROM sys_handle_permissions";
		List<Map<String , Object>> handlePermissionId_datasources = this.findForJdbc(sql1 , null);
		return handlePermissionId_datasources;
	}
	
	@Override
	public void saveHandlePermissionsAttrs(SysHandlePermissionsAttrs entity , AjaxJsonResponse ajr , Object loginUserId_obj) throws Exception {
		String id = entity.getId();
		ajr.setResMsg("保存成功!");
		if(StringUtils.isNotBlank(id)) {
			SysHandlePermissionsAttrs destEntity = this.get(id);
			String oldName = destEntity.getName();
			BeanUtils.copyProperties(entity , destEntity , "createTime" , "createUserId");
			this.updateEntitiy(destEntity);
		} else {
			entity.setCreateTime(new java.sql.Timestamp(System.currentTimeMillis()));
			entity.setCreateUserId(loginUserId_obj == null ? null : loginUserId_obj.toString());
			Serializable newId = this.save(entity);
			if(newId == null) {
				ajr.setResCode(301);
				ajr.setResMsg("保存失败!");
			}
		}
	}
}
